package com.spelet.simulation;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.spelet.StaticFonts;

public class ResizeMap {
	Sprite bgborder;
	public Sprite incSize, decSize,set,decSizeNO, incSizeNO;
	public int cols;
	public int rows;
	public ResizeMap() {
		cols = 0;
		rows = 0;
		bgborder = new Sprite(new Texture(Gdx.files.internal("data/LoadFileMap/border.png")));
		bgborder.setX(Gdx.graphics.getWidth()*0.88f/2-bgborder.getWidth()/2);
		bgborder.setY(Gdx.graphics.getHeight()/2-bgborder.getHeight()/2*0.47f);
		incSize = new Sprite(new Texture(Gdx.files.internal("data/resizemap/incSize.png")));
		decSize = new Sprite(new Texture(Gdx.files.internal("data/resizemap/decSize.png")));
		incSizeNO = new Sprite(new Texture(Gdx.files.internal("data/resizemap/incSizeNO.png")));
		decSizeNO = new Sprite(new Texture(Gdx.files.internal("data/resizemap/decSizeNO.png")));
		set = new Sprite(new Texture(Gdx.files.internal("data/resizemap/set.png")));
	}
	public boolean hit(int x, int y) {
		return bgborder.getBoundingRectangle().contains(x,y);
	}
	public void pressed(int x, int y) {
		//cols
		incSize.setPosition(bgborder.getX()+bgborder.getWidth()/4-incSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2+incSize.getHeight()/2);
		decSize.setPosition(bgborder.getX()+bgborder.getWidth()/4-decSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2-decSize.getHeight()/2-64);
		if (incSize.getBoundingRectangle().contains(x,y)) {
			cols++;
			if (cols > Map.MAX_COLS)
				cols = Map.MAX_COLS;
		} else if (decSize.getBoundingRectangle().contains(x,y)) {
			cols--;
			if (cols < Map.MIN_COLS)
				cols = Map.MIN_COLS;
		}
		//Rows
		incSize.setPosition(bgborder.getX()+bgborder.getWidth()/4+bgborder.getWidth()/2-incSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2+incSize.getHeight()/2);
		decSize.setPosition(bgborder.getX()+bgborder.getWidth()/4+bgborder.getWidth()/2-decSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2-decSize.getHeight()/2-64);
		if (incSize.getBoundingRectangle().contains(x,y)) {
			rows++;
			if (rows > Map.MAX_ROWS)
				rows = Map.MAX_ROWS;
		} else if (decSize.getBoundingRectangle().contains(x,y)) {
			rows--;
			if (rows < Map.MIN_ROWS)
				rows = Map.MIN_ROWS;
		}

	}
	public void render(OrthographicCamera cam, SpriteBatch sb) {
		bgborder.draw(sb);

		//Cols
		if (cols >= Map.MAX_COLS) {
			incSizeNO.setPosition(bgborder.getX()+bgborder.getWidth()/4-incSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2+incSize.getHeight()/2);
			incSizeNO.draw(sb);
		} else {
			incSize.setPosition(bgborder.getX()+bgborder.getWidth()/4-incSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2+incSize.getHeight()/2);
			incSize.draw(sb);
		}
		if (cols <= Map.MIN_COLS) {
			decSizeNO.setPosition(bgborder.getX()+bgborder.getWidth()/4-decSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2-decSize.getHeight()/2-64);
			decSizeNO.draw(sb);
		} else {
			decSize.setPosition(bgborder.getX()+bgborder.getWidth()/4-decSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2-decSize.getHeight()/2-64);
			decSize.draw(sb);
		}
		StaticFonts.basicFont.draw(sb, ""+cols, bgborder.getX()+bgborder.getWidth()/4-decSize.getWidth()/6,bgborder.getY()+bgborder.getHeight()/2);
		StaticFonts.basicFont.draw(sb, "Width:", bgborder.getX()+bgborder.getWidth()/4-decSize.getWidth()/6-StaticFonts.basicFont.getBounds("Width: ").width,bgborder.getY()+bgborder.getHeight()/2);
		//Rows
		if (rows >= Map.MAX_ROWS) {
			incSizeNO.setPosition(bgborder.getX()+bgborder.getWidth()/4+bgborder.getWidth()/2-incSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2+incSize.getHeight()/2);
			incSizeNO.draw(sb);
		} else {
			incSize.setPosition(bgborder.getX()+bgborder.getWidth()/4+bgborder.getWidth()/2-incSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2+incSize.getHeight()/2);
			incSize.draw(sb);
		}
		if (rows <= Map.MIN_ROWS) {
			decSizeNO.setPosition(bgborder.getX()+bgborder.getWidth()/4+bgborder.getWidth()/2-decSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2-decSize.getHeight()/2-64);
			decSizeNO.draw(sb);
		} else {
			decSize.setPosition(bgborder.getX()+bgborder.getWidth()/4+bgborder.getWidth()/2-decSize.getWidth()/2,bgborder.getY()+bgborder.getHeight()/2-decSize.getHeight()/2-64);
			decSize.draw(sb);
		}
		StaticFonts.basicFont.draw(sb, ""+rows, bgborder.getX()+bgborder.getWidth()/4+bgborder.getWidth()/2-decSize.getWidth()/6,bgborder.getY()+bgborder.getHeight()/2);
		StaticFonts.basicFont.draw(sb, "Height:", bgborder.getX()+bgborder.getWidth()/4+bgborder.getWidth()/2-decSize.getWidth()/6-StaticFonts.basicFont.getBounds("Height: ").width,bgborder.getY()+bgborder.getHeight()/2);
		set.setPosition(bgborder.getX()+bgborder.getWidth()/2-set.getWidth()/2, bgborder.getY()+bgborder.getHeight()/2-set.getHeight()/2);
		set.draw(sb);
	}
	public void setCols(int c) {
		cols= c;
	}
	public void setRows(int r) {
		rows = r;
	}
}
